package org.edu.modules.message.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.edu.modules.message.entity.VeMsgSend;
import org.edu.modules.message.mapper.VeMsgSendMapper;
import org.edu.modules.message.service.IVeMsgSendService;
import org.edu.modules.message.vo.ChannelVo;
import org.edu.modules.message.vo.MessageVo;
import org.edu.modules.message.vo.MsgSendCountVo;
import org.edu.modules.message.vo.UserVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @Description: 已发消息
 * @Author: jeecg-boot
 * @Date: 2021-05-07
 * @Version: V1.0
 */
@Service
public class VeMsgSendServiceImpl extends ServiceImpl<VeMsgSendMapper, VeMsgSend> implements IVeMsgSendService {

    @Override
    public List<MsgSendCountVo> getCountByChannel() {
        return baseMapper.getCountByChannel();
    }

    @Override
    public List<MsgSendCountVo> getCountByUser(Integer channel) {
        return baseMapper.getCountByUser(channel);
    }

    @Override
    public boolean send(MessageVo messageVo) {
        List<Integer> channelIds = JSON.parseArray(messageVo.getChannelStr(), Integer.class);
        if (channelIds == null || channelIds.size() <= 0) {
            return false;
        }
        VeMsgSend msgSend = null;
        for (Integer channelId : channelIds) {
            msgSend = new VeMsgSend();
            msgSend.setChannel(channelId);
            msgSend.setContent(messageVo.getContent());
            msgSend.setTitle(messageVo.getTitle());
            msgSend.setSendBy(messageVo.getSendBy());
            msgSend.setSendTo(messageVo.getSendTo());
            msgSend.setSendTime(new Date());
            msgSend.setFailNum(0);
            msgSend.setSuccessNum(1);
            msgSend.setSendTotalNum(1);
            baseMapper.insert(msgSend);
        }
        return true;
    }

    @Override
    public int importExcel(List<Map<String, Object>> list) {
        return 0;
    }
}
